package com.cpoopc.fuckapp;/**
 * Created by cpoopc on 2015/8/21.
 */

import android.test.AndroidTestCase;

import com.cpoopc.fuckapp.bean.Account;
import com.cpoopc.fuckapp.dao.DatabaseHelper;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.PreparedDelete;

import junit.framework.Assert;

import java.sql.SQLException;
import java.util.List;

/**
 * User: cpoopc
 * Date: 2015-08-21
 * Time: 13:36
 * Ver.: 0.1
 */
public class OrmliteTest extends AndroidTestCase {

    private Dao<Account, Integer> accountDao;
    private Account account;

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        try {
            accountDao = DatabaseHelper.getInstance(getContext()).getAccountDao();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void testInsert() {
        account = new Account();
        account.setAccountName("sb");
        account.setPassword("12321312");
        try {
            Account ifNotExists = accountDao.createIfNotExists(account);
            Assert.assertNotNull(ifNotExists);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void testQuery() {
        try {
            List<Account> accounts = accountDao.queryForEq("account_name", "sb");
            Assert.assertNotNull(accounts);
            Assert.assertEquals(accounts.size(), 1);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

//    public void testUpdate() {
////        account.setAccountName("sb_update");
//        try {
//            Dao.CreateOrUpdateStatus orUpdate = accountDao.createOrUpdate(account);
//            Assert.assertTrue(orUpdate.isUpdated());
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
//    }

//    public void testDelete() {
//        try {
//            int delete = accountDao.deleteBuilder().where().eq("","").;
//            Assert.assertEquals(1, delete);
//        } catch (SQLException e) {
//            e.printStackTrace();
//        }
//    }

}
